package com.git.demo.controller;

import com.git.demo.bean.*;
import com.git.demo.service.impl.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
//RestController是restURL风格的地址用来做前后端分离
// URL管理和规划的，前后端分离的数据交互方式用json，所有的
// 方法默认返回的json
//Controller是在非前后端分离里面使用的注解，可以返回一个
//页面视图。如果要求返回的数据里面是json，则要在对应的方法
//下加上@ResponseBody注解
public class TestController {
    @Autowired
    private TestService testService;

    @Configuration
    public class WebMvcConfig extends WebMvcConfigurerAdapter{
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            super.addCorsMappings(registry);
            registry.addMapping("/**")
                    .allowedOrigins("*")
                    .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
                    .maxAge(3600)
                    .allowCredentials(true);
        }
    }




    @RequestMapping("age_range")
    public List<AgeRange> getAgeRange(){
        List<AgeRange> ageRanges = testService.getALLAgeRange();
        return ageRanges;
    }

    @RequestMapping("province")
    public List<Province> getProvince(){
        List<Province> provinces = testService.getALLProvince();
        return provinces;
    }

    @RequestMapping("gender")
    public List<Gender> getGender(){
        List<Gender> genders = testService.getALLGender();
        return genders;
    }

    @RequestMapping("top")
    public List<Top> getTop(){
        List<Top> tops = testService.getALLTop();
        return tops;
    }
    @RequestMapping("age_count")
    public List<AgeCount> getAgeCounts() {
        List<AgeCount> ageCounts = testService.getALLCount();
        return ageCounts;
    }

}
